#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Gezel.Model 
{
  /// <summary>
  /// The signalflowgraph encapsulates a set of expresssions
  /// (signal assignments and directives). Gezel also allows
  /// declaration of a single register or signal inside a
  /// signal flow graph, which is currently not supported
  /// in this implementation.
  /// </summary>
  public partial class SignalFlowGraph : AbstractEntity<Datapath>
  {
    /// <summary>
    /// Signalflow graphs may contain one 
    /// local signal which can only be accessed
    /// from within the sfg.
    /// </summary>    
    private Signal signal;
    public Signal Signal
    {
      get
      {
        return signal;
      }
      set
      {
        signal = value;
      }
    }

    /// <summary>
    /// Signalflow graphs may contain one 
    /// local register which can only be accessed
    /// from within the sfg.
    /// </summary>    
    private Register register;
    public Register Register
    {
      get
      {
        return register;
      }
      set
      {
        register = value;
      }
    }

    /// <summary>
    /// The expressions contained in the signalflowgraph.
    /// </summary>
    private List<Expression> expressions;
    public List<Expression> Expressions
    {
      get
      {
        return expressions;
      }
    }

    /// <summary>
    /// True iff this sfg is driven by
    /// a hardwired controller. Set during
    /// the verification phase.
    /// </summary>
    private bool isHardwired;
    public bool IsHardwired
    {
      get
      {
        return isHardwired;
      }
      internal set
      {
        isHardwired = value;
      }
    }

    /// <summary>
    /// Constructs a new SignalFlowGraph with the
    /// specified datapath as parent.
    /// </summary>
    /// <param name="parent">the parent datapath</param>
    /// <param name="name">the local name of the signalflowgraph</param>
    public SignalFlowGraph(Datapath parent, string name) : base(parent, name)
    {
      expressions = new List<Expression>();
    }

		public SignalFlowGraph(
			Datapath parent, 
			string name,
			Position startPosition,
			Position endPosition
		)
			: base(parent, name, startPosition, endPosition)
    {
      expressions = new List<Expression>();
    }

    public SignalFlowGraph Clone(Datapath newParent)
    {
      SignalFlowGraph clone = 
				new SignalFlowGraph(newParent, localName, startPosition, endPosition);

      if (this.signal != null)
        clone.signal = this.signal.Clone(clone);

      foreach (Expression expr in expressions)
        clone.expressions.Add(expr.Clone());

      return clone;
    }
  }
}